#!/bin/bash
## 用于下载安装包
arch=`uname -m`
os_type=`cat /etc/os-release  | grep ^ID | sed 's/ID=//' | sed -n 1p`

input_passwd(){
    echo '请输入当前系统密码(直接回车可以使用默认值):'
    read passwd
    if [[ -z ${passwd} ]];then
        password='Gxxc@123'
    else
        password=${passwd}
    fi
    echo $password | sudo -S echo "校验成功..."
    if [[ $? == 0 ]];then
        echo '继续...'
        update=`echo ${password} | sudo -S apt update `
        root_pass=0
    else
        apts='apt  download  '
        root_pass=1
        echo '密码校验失败,可能会下载失败,继续请直接回车,否则请按快捷键：Ctrl+c'
        read c
    fi
}
download(){
    apt download $1
    if [[ $? == 0 ]];then
        echo "安装包下载成功: $1"
    else
        echo "安装包下载失败: $1"
    fi
}
search_status(){
    if [[ $? == 0 ]];then
        echo '搜索完成'
    else
        echo '搜索出错,请检查网络'
    fi
}
if [[ -z $1 ]];then
    echo -e "请传入包名,例如: 

bash pac_download.sh com.weixin

bash pac_download.sh com.weixin

支持一次传入多个包，例如: 

bash pac_download.sh com.weixin com.qq wps

可以使用下面的命令查询包名,例如: 

apt search 安全浏览器"
    exit 1
fi
if [[ $1 == '-s' ]];then
    if [[ -n $2 ]];then
        if [[ -n $3 ]];then
            apt search $2 | grep $3
            search_status
        else
            apt search $2 
            search_status
        fi
        exit 0
    else
        echo '请传入包名关键字进行搜索'
        exit 1
    fi
fi

for i in $*;do
    download $i
done
echo '执行完成'
ls